#!/bin/bash

# 模型资源配置地址
folder_path="/opt/seamless_communication/src/seamless_communication/cards"

# 替换为本地地址
replace_rules=(
  's#uri: "https://dl.fbaipublicfiles.com/seamless/datasets/mexpresso_text/mexpresso_text.tar"#uri: "file://opt/seamless_communication/models/mexpresso_text.tar"#g'
  's#sp_model: https://huggingface.co/facebook/seamless-m4t-medium/resolve/main/tokenizer.model#sp_model: http://127.0.0.1:8081/models/tokenizer.model#g'
  's#char_tokenizer: "https://huggingface.co/facebook/seamless-streaming/resolve/main/spm_char_lang38_tc.model"#char_tokenizer: "file://opt/seamless_communication/models/spm_char_lang38_tc.model"#g'
  's#checkpoint: "https://dl.fbaipublicfiles.com/seamless/models/unity2_aligner.pt"#checkpoint: "file://opt/seamless_communication/models/unity2_aligner.pt"#g'
  's#checkpoint: "https://huggingface.co/facebook/seamless-streaming/resolve/main/seamless_streaming_monotonic_decoder.pt"#checkpoint: "file://opt/seamless_communication/models/seamless_streaming_monotonic_decoder.pt"#g'
  's#checkpoint: "https://huggingface.co/facebook/seamless-streaming/resolve/main/seamless_streaming_unity.pt"#checkpoint: "file://opt/seamless_communication/models/seamless_streaming_unity.pt"#g'
  's#checkpoint: "https://huggingface.co/facebook/seamless-m4t-large/resolve/main/multitask_unity_large.pt"#checkpoint: "file://opt/seamless_communication/models/large/multitask_unity_large.pt"#g'
  's#checkpoint: "https://huggingface.co/facebook/seamless-m4t-medium/resolve/main/multitask_unity_medium.pt"#checkpoint: "file://opt/seamless_communication/models/medium/multitask_unity_medium.pt"#g'
  's#char_tokenizer: "https://huggingface.co/facebook/seamless-m4t-v2-large/resolve/main/spm_char_lang38_tc.model"#char_tokenizer: "file://opt/seamless_communication/models/v2/spm_char_lang38_tc.model"#g'
  's#checkpoint: "https://huggingface.co/facebook/seamless-m4t-v2-large/resolve/main/seamlessM4T_v2_large.pt"#checkpoint: "file://opt/seamless_communication/models/seamlessM4T_v2_large.pt"#g'
  's#tokenizer: "https://huggingface.co/facebook/seamless-m4t-large/resolve/main/tokenizer.model"#tokenizer: "/opt/seamless_communication/models/large/tokenizer.model"#g'
  's#tokenizer: "https://huggingface.co/facebook/seamless-m4t-medium/resolve/main/tokenizer.model"#tokenizer: "/opt/seamless_communication/models/medium/tokenizer.model"#g'
  's#checkpoint: "https://huggingface.co/facebook/seamless-m4t-vocoder/resolve/main/vocoder_36langs.pt"#checkpoint: "file://opt/seamless_communication/models/vocoder/vocoder_36langs.pt"#g'
  's#checkpoint: "https://dl.fbaipublicfiles.com/seamless/models/vocoder_v2.pt"#checkpoint: "file://opt/seamless_communication/models/vocoder_v2.pt"#g'
  's#checkpoint: "https://dl.fbaipublicfiles.com/seamlessM4T/models/unit_extraction/xlsr2_1b_v2.pt"#checkpoint: "file://opt/seamless_communication/models/xlsr2_1b_v2.pt"#g'
)

# 进入目标文件夹
cd "$folder_path" || exit

# 遍历文件夹内的文件
for file in *; do
    # 检查是否为文件
    if [ -f "$file" ]; then
        # 逐条应用替换规则
        for rule in "${replace_rules[@]}"; do
            sed -i "$rule" "$file"
        done
        echo "替换文件 $file 中的内容"
    fi
done

echo "替换完成！"
